/**
 * @file simple-popover
 * @author liaoxuezhi@baidu.com
 */
/* eslint fecs-indent: [0, "space", 2, 2] */

import * as React from 'react';
import {
  PureComponent,
  PropTypes
} from 'react';
import {findDOMNode} from 'react-dom';
import * as omit from 'lodash/omit';

export default class Html extends PureComponent {
  static propTypes = {
    className: PropTypes.string,
    html: PropTypes.string
  };

  componentDidMount() {
    this.setHtml();
  }

  componentDidUpdate() {
    this.setHtml();
  }

  setHtml() {
    const dom = findDOMNode(this);
    const html = this.props.html;
    dom.innerHTML = html || '';
  }

  render() {
    const rest = omit(this.props, ['className', 'html', 'tagName']);
    const Component = this.props.tagName || 'div';

    return (<Component {...rest} className={this.props.className}></Component>);
  }
}
